# -*- coding: utf-8 -*-
"""
UTc! module: src.sandbox.ode_rendering

Purpose
=======
 Provides facilities for visually rendering ODE elements in the sandbox
 environment.
 
Legal
=====
 All code, unless otherwise indicated, is original, and subject to the
 terms of the GPLv2, which is provided in COPYING.
 
 (C) Neil Tallim, 2009
"""
import ode
import OpenGL.GL as GL

import generic_rendering

def renderODE(objects, r, g, b):
	"""
	Renders arbitrary ODE Geoms.
	
	@type objects: sequence
	@param objects: A collection of ode.GeomObjects to be rendered.
	@type r: float
	@param r: The red-value to use when rendering.
	@type g: float
	@param g: The green-value to use when rendering.
	@type b: float
	@param b: The blue-value to use when rendering.
	"""
	for obj in objects:
		if type(obj) == ode.GeomBox:
			_renderBox(obj, r, g, b)
		else:
			_renderSphere(obj, r, g, b)
			
def _renderBox(box, r, g, b):
	"""
	Renders an arbitrary ODE GeomBox.
	
	@type box: ode.GeomBox
	@param box: The ODE GeomBox to be rendered.
	@type r: float
	@param r: The red-value to use when rendering.
	@type g: float
	@param g: The green-value to use when rendering.
	@type b: float
	@param b: The blue-value to use when rendering.
	"""
	GL.glPushMatrix()
	generic_rendering.initMatrixQuat(box.getPosition(), box.getRotation())
	generic_rendering.renderBox(box.getLengths(), r, g, b)
	GL.glPopMatrix()
	
def _renderSphere(sphere, r, g, b):
	"""
	Renders an arbitrary ODE GeomSphere.
	
	@type sphere: ode.GeomSphere
	@param sphere: The ODE GeomSphere to be rendered.
	@type r: float
	@param r: The red-value to use when rendering.
	@type g: float
	@param g: The green-value to use when rendering.
	@type b: float
	@param b: The blue-value to use when rendering.
	"""
	GL.glPushMatrix()
	generic_rendering.initMatrixQuat(sphere.getPosition(), sphere.getRotation())
	generic_rendering.renderSphere(sphere.getRadius(), r, g, b)
	GL.glPopMatrix()
	